package com.jgssp.demo;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.anythink.core.api.ATAdInfo;
import com.anythink.core.api.AdError;
import com.anythink.rewardvideo.api.ATRewardVideoAd;
import com.anythink.rewardvideo.api.ATRewardVideoListener;

public class RewardActivity extends AppCompatActivity {

    private String TAG = "RewardActivity";
    private ATRewardVideoAd mRewardVideoAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intersitial);


        mRewardVideoAd = new ATRewardVideoAd(this, "b66f62ce658899");
        mRewardVideoAd.setAdListener(new ATRewardVideoListener() {
            @Override
            public void onRewardedVideoAdLoaded() {
                Log.e(TAG, "onRewardedVideoAdLoaded:");
            }

            @Override
            public void onRewardedVideoAdFailed(AdError adError) {
                Log.e(TAG, "onRewardedVideoAdFailed:");
            }

            @Override
            public void onRewardedVideoAdPlayStart(ATAdInfo atAdInfo) {
                Log.e(TAG, "onRewardedVideoAdPlayStart:");
            }

            @Override
            public void onRewardedVideoAdPlayEnd(ATAdInfo atAdInfo) {
                Log.e(TAG, "onRewardedVideoAdPlayEnd:");
            }

            @Override
            public void onRewardedVideoAdPlayFailed(AdError adError, ATAdInfo atAdInfo) {
                Log.e(TAG, "onRewardedVideoAdPlayFailed:");
            }

            @Override
            public void onRewardedVideoAdClosed(ATAdInfo atAdInfo) {
                Log.e(TAG, "onRewardedVideoAdClosed:");
            }

            @Override
            public void onRewardedVideoAdPlayClicked(ATAdInfo atAdInfo) {
                Log.e(TAG, "onRewardedVideoAdPlayClicked:");
            }

            @Override
            public void onReward(ATAdInfo atAdInfo) {
                Log.e(TAG, "onReward:");
            }
        });


        findViewById(R.id.btn_load).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mRewardVideoAd.load();
            }
        });

        findViewById(R.id.btn_show).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mRewardVideoAd.isAdReady()) {
                    mRewardVideoAd.show(RewardActivity.this);
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
